/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ProcessFlowDlg.java
 *
 * Created on 2010-9-16, 21:13:59
 */
package dataanalysis.gui.dialog;

import dataanalysis.main.MainView;

/**
 *
 * @author Administrator
 */
public class ProcessFlowDlg extends javax.swing.JDialog {

    private final MainView m_manager;
    private int m_backupPre = 1;
    private int m_backupAS = 1;
    private int m_backupCls = 1;

    /** Creates new form ProcessFlowDlg */
    public ProcessFlowDlg(java.awt.Frame parent, boolean modal, final MainView manager) {
        super(parent, modal);
        m_manager = manager;
        initComponents();
        this.setTitle("处理流程");
        this.setLocationRelativeTo(parent);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel3 = new javax.swing.JPanel();
        m_clsCheckBox = new javax.swing.JCheckBox();
        jLabel3 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        m_feaCheckBox = new javax.swing.JCheckBox();
        jLabel2 = new javax.swing.JLabel();
        m_supRadio = new javax.swing.JRadioButton();
        m_semiRadio = new javax.swing.JRadioButton();
        jPanel1 = new javax.swing.JPanel();
        m_preCheckBox = new javax.swing.JCheckBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel3.setPreferredSize(new java.awt.Dimension(350, 80));

        m_clsCheckBox.setSelected(true);
        m_clsCheckBox.setText("分类器");
        m_clsCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_clsCheckBoxActionPerformed(evt);
            }
        });

        jLabel3.setText("用训练数据构建分类器，可检验特征选择效果");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jLabel3))
                    .addComponent(m_clsCheckBox))
                .addContainerGap(97, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(m_clsCheckBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3)
                .addContainerGap(26, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel2.setPreferredSize(new java.awt.Dimension(350, 80));

        m_feaCheckBox.setSelected(true);
        m_feaCheckBox.setText("特征选择");
        m_feaCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_feaCheckBoxActionPerformed(evt);
            }
        });

        jLabel2.setText("从所有变量中挑选出能够区分出类别信息的特征组合");

        buttonGroup1.add(m_supRadio);
        m_supRadio.setText("有监督");
        m_supRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_supRadioActionPerformed(evt);
            }
        });

        buttonGroup1.add(m_semiRadio);
        m_semiRadio.setSelected(true);
        m_semiRadio.setText("半监督");
        m_semiRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_semiRadioActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jLabel2))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(m_feaCheckBox)
                        .addGap(33, 33, 33)
                        .addComponent(m_semiRadio)
                        .addGap(26, 26, 26)
                        .addComponent(m_supRadio)))
                .addContainerGap(61, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(m_feaCheckBox)
                    .addComponent(m_semiRadio)
                    .addComponent(m_supRadio))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2)
                .addContainerGap(26, Short.MAX_VALUE))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setPreferredSize(new java.awt.Dimension(350, 80));

        m_preCheckBox.setSelected(true);
        m_preCheckBox.setText("数据预处理");
        m_preCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_preCheckBoxActionPerformed(evt);
            }
        });

        jLabel1.setText("对原始数据进行预处理之后再进行其它操作");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jLabel1))
                    .addComponent(m_preCheckBox))
                .addContainerGap(109, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(m_preCheckBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel1)
                .addContainerGap(26, Short.MAX_VALUE))
        );

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dataanalysis/gui/img/dialog.jpg"))); // NOI18N

        jButton1.setText("取  消");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("确  定");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 134, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 368, Short.MAX_VALUE)
                            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 368, Short.MAX_VALUE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 368, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(101, 101, 101)
                        .addComponent(jButton1)
                        .addGap(18, 18, 18)
                        .addComponent(jButton2)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 337, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void m_clsCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_clsCheckBoxActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_m_clsCheckBoxActionPerformed

    private void m_feaCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_feaCheckBoxActionPerformed
        // TODO add your handling code here:
        m_supRadio.setEnabled(m_feaCheckBox.isSelected());
        m_semiRadio.setEnabled(m_feaCheckBox.isSelected());
}//GEN-LAST:event_m_feaCheckBoxActionPerformed

    private void m_supRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_supRadioActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_m_supRadioActionPerformed

    private void m_semiRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_semiRadioActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_m_semiRadioActionPerformed

    private void m_preCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_preCheckBoxActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_m_preCheckBoxActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.setVisible(false);
        this.recoverState();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        this.setVisible(false);
        this.setProcessFlowValue();

    }//GEN-LAST:event_jButton2ActionPerformed
//    /**
//     * @param args the command line arguments
//     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
//                ProcessFlowDlg dialog = new ProcessFlowDlg(new javax.swing.JFrame(), true, null);
//                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
//
//                    public void windowClosing(java.awt.event.WindowEvent e) {
//                        System.exit(0);
//                    }
//                });
//                dialog.setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JCheckBox m_clsCheckBox;
    private javax.swing.JCheckBox m_feaCheckBox;
    private javax.swing.JCheckBox m_preCheckBox;
    private javax.swing.JRadioButton m_semiRadio;
    private javax.swing.JRadioButton m_supRadio;
    // End of variables declaration//GEN-END:variables

    private void setProcessFlowValue() {
        int a = 0, b = 0, c = 0;
        if (m_preCheckBox.isSelected()) {
            a = 1;
        }
        if (m_feaCheckBox.isSelected()) {
            if (m_semiRadio.isSelected()) {
                b = 1;
            }
            if (m_supRadio.isSelected()) {
                b = 2;
            }
        }
        if (m_clsCheckBox.isSelected()) {
            c = 1;
        }
        m_backupPre = a;
        m_backupAS = b;
        m_backupCls = c;
        m_manager.setProcessFlowValue(a, b, c);
    }

    private void recoverState() {
        m_preCheckBox.setSelected(m_backupPre != 0);
        m_feaCheckBox.setSelected(m_backupAS != 0);
        m_clsCheckBox.setSelected(m_backupCls != 0);
        m_semiRadio.setEnabled(m_backupAS != 0);
        m_supRadio.setEnabled(m_backupAS != 0);
        if (m_backupAS == 1) {
            m_semiRadio.setSelected(true);
        } else if (m_backupAS == 2) {
            m_supRadio.setSelected(true);
        }
    }
}
